<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
	defined ('IN_AGORA') or die;

	class OnlineModel extends Model
	{
		function __construct()
		{
			parent::__construct('users');
		}

		function getOnline()
		{
			$sessions = null;
			// calculate number of guests and members
			$user_array  = array();
			$guest_count = 0;

			$this->db->setQuery('SELECT COUNT(*) FROM #__session WHERE guest=1');
			$guest_count = $this->db->loadResult();
			
/*			$query = 'SELECT a.id, a.username, j_u.name' .
						' FROM #__session AS s INNER JOIN ##__users AS a ON s.userid=a.jos_id' .
                        ' LEFT JOIN #__users AS j_u'.
                    		' ON s.userid = j_u.id'.
			
						' WHERE client_id = 0 AND s.guest=0';
*/		
		    $query 		= ' SELECT DISTINCT au.id, u.username, u.name, u.email'
					. ' FROM #__session s, #__users u, #__agora_users au '
					. ' WHERE s.userid = u.id AND u.id = au.jos_id AND s.client_id = 0'
					//. ' AND s.time >= '.(int)$from_time.' '
					;
			

			$this->db->setQuery($query);
			$sessions = $this->db->loadObjectList();

			if (count($sessions)) {
			    foreach ($sessions as $session) {
					$user_array[] = array('id' => $session->id, 'name' => $session->username, 'fullname' => $session->name);
				}
			}

			$result      = array();
			$result['users']  = $user_array;
			$result['user_count']  = count($user_array);
			$result['guest_count'] = $guest_count;

			return $result;
		}

	};
?>